@extends('layout.layout')
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
   <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> 
</head>
<body>
<div>
<h1>图片信息</h1>

</div>

	<table class="table table-hover" style="margin-top: 50px">
  	<tr>
  		<th>ID</th>
  		<th>图片名称</th>
  		<th>是否展示</th>
  		<th>操作</th>
  	</tr>
  	@foreach($data as $v)
  	<tr wheel_id="{{$v->wheel_id}}">
  		<td>{{$v->wheel_id}}</td>
  		<td> <img src="/{{$v->wheel_img}}" style="width:50px"></td>
  		<td class="changevalues" field="is_show">@if($v->is_show==1)√@else×@endif
      </td>
  		<td><button class="btn btn-success"><a href="#">编辑</a></button>
  			<button class="btn btn-danger"><a href="#">删除</a></button>			
  		</td>
  	</tr>
  	@endforeach
	</table> 
</body>
</html>
<script type="text/javascript">
//单选框即点即改

$(document).on("click",".changevalues",function(){
  
    var _this=$(this);//当前点击的td
    var _val=_this.text();//值??处理
    var _field=_this.attr("field");
    var wheel_id=_this.parent("tr").attr("wheel_id");
    if(_val=="√"){
      var _value=2;//用于修改数据库
      var flog='×';
    }else{
      var _value=1;
      var flog='√';
    }
   
    $.ajax({
    url:"{{url('admin/changevalue')}}",
    data:{value:_value,field:_field,wheel_id:wheel_id},
    dataType:"json",
    success:function(res){
      if(res.code==2){
        alert(res.font);
      }else{
        _this.text(flog);
      }

        }

    })
})  
</script>